package com.workflow.engine.parser.utils;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Created by houjinxin on 2016/12/31.
 */
public class ReflectionUtil {
    /**
     * 通过反射执行对象某一属性的readMethod
     *
     * @param propName 对象的任意一个属性
     * @param bean     javaBean对象
     * @return
     * @throws IntrospectionException
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    public static Object executeReadMethod(String propName, Object bean) throws IntrospectionException, InvocationTargetException, IllegalAccessException {
        PropertyDescriptor pd = new PropertyDescriptor(propName, bean.getClass());
        Method method = pd.getReadMethod();
        return method.invoke(bean);
    }
}
